package cn.lili.modules.member.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
 * 会员搜索VO
 *
 * @author Bulbasaur
 * @since 2020/12/15 10:48
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class UserSearchParams extends PageVO {

    @Serial
    private static final long serialVersionUID = 5413229375865178589L;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "用户手机号码")
    private String mobile;

    @ApiModelProperty(value = "会员状态")
    private Boolean enable;

    @ApiModelProperty(value = "部门id")
    private String departmentId;

    @ApiModelProperty(value = "场景")
    private SceneEnums scene;


    @ApiModelProperty(value = "场景ID")
    private String extendId;
    @ApiModelProperty(value = "上级id")
    private String parentId;

    @ApiModelProperty("上级昵称")
    private String parentUsername = "";

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (CharSequenceUtil.isNotEmpty(username)) {
            queryWrapper.eq("username", username);
        }
        if (CharSequenceUtil.isNotEmpty(nickName)) {
            queryWrapper.eq("nick_name", nickName);
        }
        if (CharSequenceUtil.isNotEmpty(mobile)) {
            queryWrapper.eq("mobile", mobile);
        }
        if (enable != null) {
            queryWrapper.eq("enable", enable);
        }
        if (CharSequenceUtil.isNotEmpty(departmentId)) {
            queryWrapper.eq("department_id", departmentId);
        }
        queryWrapper.eq(StringUtils.isNotEmpty(parentId), "parent_id", parentId);
        queryWrapper.eq("scene", scene.name());
        queryWrapper.eq(extendId != null, "extend_id", extendId);
        return queryWrapper;
    }
}
